<?

require_once("mysql.php");
require_once("images.php");

$search = strtolower($_GET['search']);

$search = ESC($search);

$simple = str_replace(".com", "", $search);

$result = array();

$r = MYSQL_Q("SELECT photo FROM sellerinfo WHERE name='".$simple."' ORDER BY count DESC");
if (!$r) die("[]");

$strong = 0; // strong meaning we are very confident about these images

while ($seller = mysql_fetch_assoc($r)) {
    array_push($result, $seller['photo']);
    $strong++;
}
 
if ($strong == 0) {

    $s = bing_image_search($simple." logo");
    
    foreach($s as $i) {
        array_push($result, $i);
    }
}

$result = array_slice($result, 0, 10);

$header = array($_GET['search']);

$result = array_merge($header, $result);

 
echo json_encode($result, true);


?>
